package com.lh.project.controller;


import com.lh.project.common.BaseResponse;
import com.lh.project.common.ErrorCode;
import com.lh.project.common.ResultUtils;
import com.lh.project.common.UserHolder;
import com.lh.project.model.entity.Comment;
import com.lh.project.model.entity.CommentReply;
import com.lh.project.model.enums.SystemConstants;
import com.lh.project.service.CommentReplyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/commentReply")
public class commentReplyController {
    @Resource
    private CommentReplyService commentReplyService;

    @PostMapping("/post")
    public BaseResponse<String> createCommentReply(@RequestBody CommentReply commentReply){
        commentReply.setUserId(UserHolder.getUser().getId());
        System.out.println("前端传来的数据："+commentReply);
        Boolean flag = commentReplyService.createCommentReply(commentReply);
        return flag? ResultUtils.success("评论成功!"):ResultUtils.error(ErrorCode.SYSTEM_ERROR,"出错了");
    }

    /**
     *
     * @param commentId 表示被点赞的评论id
     * @return
     */
    @PostMapping("/like")
    public BaseResponse<String> likeComment(@RequestBody Long commentId){
        return commentReplyService.likeComment(UserHolder.getUser().getId(),commentId);
    }
}
